import { createRouter, createWebHistory, routerKey } from 'vue-router';
import Center from '../views/Center.vue';
import Find from '../views/Find.vue';
import Login from '../views/Login.vue';
import Message from '../views/Message.vue';
import Recommend from '../views/Recommend.vue';
import Personal from '../views/Personal.vue'
import SafeCode from '../views/SafeCode.vue'
import Share from '../views/Share.vue'
import Friends from '../views/message/Friends.vue'
import Forget from '../views/Forget.vue'



const routes =  createRouter({
    history: createWebHistory(),
    routes: [
        {
            path: '/',
            redirect: '/recommend'
        },
        {
            path: '/forget',
            component: Forget
        },
        {
            path: '/friends',
            component: Friends
        },
        {
            path: '/center',
            component: Center
        },
        {
            path: '/safecode',
            component: SafeCode
        },
        {
            path: '/share',
            component: Share
        },
        {
            path: '/personal',
            component: Personal
        },
        {
            path: '/find',
            component: Find
        },
        {
            path: '/login',
            component: Login
        },
        {
            path: '/message',
            component: Message
        },
        {
            path: '/recommend',
            component: Recommend
        }
    ]
});
routes.beforeEach((to, from, next) => {
    let auth = ['/center', '/friends', '/message']
    if(auth.includes(to.fullPath)) {
      if(!localStorage.getItem('userId')){
        next('/login')
      }else {
        next()
      }
    }else {
      next()
    }
})


export default routes
